<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>登录</title>
  <script src="./jquery.js" charset="utf-8"></script>
  <script type="text/javascript">
  $(function (){
    $('#login').click(function(){
      $.ajax({
         url: '/login',
         data: {user: $('#user').val(),pass: $('#pass').val()},
         dataType: 'json',
         success(json){
           if(json.err){
             alert('登陆失败'+json.msg);
           }else{
             alert('登陆成功');
           }
         },
         error(err){
           alert('失败');
         }
       });
     });
    $('#reg').click(function(){
      $.ajax({
        url: '/reg',
        dataType: 'json',
        data: {username: $('#username').val(),password:$('#password').val()},
        success(json){
          if(json.error!==0){
            alert('注册失败'+json.msg);
          }else{
            alert('注册成功');
          }
        },
        error(err){
          alert('失败');
        }
      });
    });
  });
  </script>
</head>
<body>
用户：<input type="text" id='username'/><br>
密码：<input type="password" id='password'/><br>
<input type="button" id='login' value="登录"/><input type="button" id='reg' value="注册"/>
</body>
</html>
